const http= require('http');
const ejs= require('ejs');
const url= require('url');

http.createServer(function (req, res) { 
    res.writeHead(200,'Content-Type:text/html;charset="utf8"')
    var pathname=url.parse(req.url,true).pathname
    if(pathname=='/login'){
        ejs.renderFile('views/form.ejs',{ },(err,data)=>{
            
            res.end(data)
        });

    }else if (pathname=='/dologin') {
        if (req.method=='GET') {//req.method判断请求方式
            console.log(url.parse(req.url,true).query)//get 获取传值
        }
        if(req.method=='POST'){//POST 获取传值
            var postData=''
            req.on('data',(data)=>{
                postData+=data
            })
            req.on('end',()=>{
                console.log(postData)
            })
        }
        
        res.end('register')
    }else{
        ejs.renderFile('views/index.ejs',{  },(err,data)=>{
            // console.log(err)
            res.end(data)
        });
    }
}).listen(8081);